<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="gl_searchBox gl_mb_15">
      <el-row :gutter="20">
        <el-col :md="6" :lg="4">
          <p>教室名称</p>
          <el-input v-model="form.Filter" placeholder="请输入教室名称" size="mini" clearable @change="getList()" />
        </el-col>
        <el-col :md="8" :lg="6">
          <el-button style="margin-top:27px" type="primary" size="mini" @click="getList()">筛选</el-button>
          <!-- <el-button style="margin-top:27px" type="warning" size="mini" @click="reset()">重置</el-button> -->
        </el-col>
      </el-row>
    </div>
    <div class="gl_mb_15">
      <el-button type="primary" size="mini" @click="addClassRoom()">新建教室</el-button>
    </div>
    <el-table v-loading="loading" class="gl_table_noBorder" :data="tableData" size="mini">
      <el-table-column prop="name" label="教室名称" />
      <el-table-column prop="address" label="详细地址" />
      <el-table-column prop="maxStudentCount" label="可容纳人数" width="200" />
      <el-table-column label="操作" width="200">
        <template slot-scope="{row}">
          <el-button size="mini" type="text" @click="edit(row)">编辑</el-button>
          <el-button size="mini" type="text" @click="remove(row)">
            <span class="gl_color_error">删除</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <AddClassRoom ref="addClassRoom" :form-data="formData" :title="title" />
  </div>
</template>

<script>
import AddClassRoom from './addClassRoom';
import { CopyData } from '@/lib/index';
import {
  api_GET_ClubClassroom, // 获取
  api_DELETE_ClubClassroomId // 删除
} from '@/extend/api/hallswaggerApi/app.js';
import {
  // Api_GET_ClubClassroomQO, // 获取
  CreateClassroomInput // 新建
} from '@/lib/form/hall/swaggerForm.js';
export default {
  name: 'Classroom',
  components: {
    AddClassRoom
  },
  data() {
    return {
      loading: false,
      // form: new Api_GET_ClubClassroomQO(),
      form: {
        Filter: ''
      },
      tableData: [],
      formDialog: new CreateClassroomInput(), // 弹窗form
      title: '', // 弹窗标题
      formData: {} // 弹窗所用表单
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 获取数据
    getList() {
      var that = this;
      that.loading = true;
      api_GET_ClubClassroom(that.form).then(res => {
        that.tableData = res.items;
        that.loading = false;
      }).catch(error => {
        that.loading = false;
        that.$message({ type: 'error', message: error.error.message });
      });
    },
    // 新建教室
    addClassRoom() {
      this.formData = {};
      this.$refs.addClassRoom.open();
      this.title = '新建教室';
      this.formData = new CreateClassroomInput();
    },
    // 编辑教室
    edit(row) {
      this.formData = {};
      this.$refs.addClassRoom.open(row.id);
      CopyData(row, this.formDialog);
      this.title = '编辑教室';
      this.formData = this.formDialog;
    },
    // 删除教室
    remove(row) {
      var that = this;
      that.$confirm(`您确定要删除 ${row.name}？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        api_DELETE_ClubClassroomId(row.id).then(res => {
          that.getList();
          that.$message({ type: 'success', message: '删除成功!' });
        }).catch(error => {
          that.$message({ type: 'error', message: '删除失败 ' + error.error.message });
        });
      }).catch(() => {});
    }
  }
};
</script>

<style scoped>

</style>
